package com.bupt.cad.controller;

import com.alibaba.fastjson.JSONObject;
import com.bupt.cad.common.ApiResult;
import com.bupt.cad.entity.Com;
import com.bupt.cad.service.impl.ScreenToBlueService;
import com.bupt.cad.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class ScreenToBlueController {
    @Autowired
    ScreenToBlueService screenToBlueService;

    @ResponseBody
    @PostMapping(value = "/saveBlueComps")
    public ApiResult saveBlueComps(@RequestBody JSONObject object){
        if(screenToBlueService.insertBlueComps(object)){
            return ResultUtil.success("save BlueComps successfully");
        }else{
            return ResultUtil.error(-1,"save BlueComps failed");
        }
    }

    @ResponseBody
    @GetMapping(value = "/getBlueComps")
    public ApiResult getBlueComps(@RequestParam int screenId){
        List<Com> coms = screenToBlueService.getAllBlueComps(screenId);
        if(coms !=null){
            return ResultUtil.success(coms,"get blueComps successfully");
        }else{
            return ResultUtil.error(-1,"get blueComp failed");
        }
    }
}
